package com.admin.business.portalWebsite.venusSysModel;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 范本表
 * @create: 2023-11-18 16:45:42
 **/
@Service("venusSysModelService")
@Slf4j
public class VenusSysModelService{

    @Resource
    VenusSysModelDao venusSysModelDao;

    /**
     * 添加范本表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:发布者用户ID
     *                   - classify_id:分类ID
     *                   - classify_ids:分类IDs
     *                   - model_cost:下载费用
     *                   - model_name:范本名称
     *                   - model_browse:浏览数量
     *                   - publisher_name:发布人姓名
     *                   - model_download:下载数量
     *                   - model_download_url:上传范本url
     *                   - model_details:范本展示
     *                   - model_status:范本类型名称
     *                   - model_pay:是否收费下载：0，不收费，1、收费
     *                   - deduction_user_id:扣除人
     *                   - deduction_time:扣除时间
     *                   - deduction_state:扣除状态 0未扣除 1已扣除
     *                   - deduction_money:扣除金额
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return addVenusSysModel(CDO cdoRequest) {
        venusSysModelDao.addVenusSysModel(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新范本表数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:发布者用户ID
     *                   - classify_id:分类ID
     *                   - classify_ids:分类IDs
     *                   - model_cost:下载费用
     *                   - model_name:范本名称
     *                   - model_browse:浏览数量
     *                   - publisher_name:发布人姓名
     *                   - model_download:下载数量
     *                   - model_download_url:上传范本url
     *                   - model_details:范本展示
     *                   - model_status:范本类型名称
     *                   - model_pay:是否收费下载：0，不收费，1、收费
     *                   - deduction_user_id:扣除人
     *                   - deduction_time:扣除时间
     *                   - deduction_state:扣除状态 0未扣除 1已扣除
     *                   - deduction_money:扣除金额
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return updateVenusSysModelById(CDO cdoRequest) {
        venusSysModelDao.updateVenusSysModelById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除范本表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysModelById(CDO cdoRequest){
        int count = venusSysModelDao.deleteVenusSysModelById(cdoRequest.getString("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除范本表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysModel(CDO cdoRequest) {
        int count = venusSysModelDao.deleteVenusSysModel(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取范本表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysModelDao.getVenusSysModelById(cdoRequest.getString("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取范本表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysModelDao.getVenusSysModelListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysModelDao.getVenusSysModelCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取范本表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysModelDao.getVenusSysModelListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysModelDao.getVenusSysModelCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
